package com.ht.right.aop;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;


import org.apache.struts2.ServletActionContext;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.ht.right.entity.User;
import com.ht.right.util.ReflectObjUtil;
import com.opensymphony.xwork2.ActionSupport;

@Aspect
@Component
public class MyAspectInterceptor extends ActionSupport {

	private static final long serialVersionUID = 1L;

	public void beforeSave(JoinPoint jp) {
		Object[] args = jp.getArgs();
		Object obj = null;
		if (args.length > 0) {
			HttpSession session = ServletActionContext.getRequest().getSession();
			obj = args[0];
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("delFlag", "1");	//添加默认删除标记属性
			map.put("createBy", ((User)session.getAttribute("user")).getUserName());	//添加创建人
			map.put("createDate", new Date());		//添加创建时间
			ReflectObjUtil.setAttrributesValues(obj, map);
		}
		//System.out.println("在切面类方法[前]执行的");
	}

	public void after(JoinPoint jp) {
		Object[] args = jp.getArgs();
		for (int i = 0; i < args.length; i++) {
			System.out.println("after:" + args[i].getClass().getName());
		}
		//System.out.println("在切面类方法[后]执行的");
	}

}